package com.jackstraw.jack_base.mq.rocketmq.consumer;

import com.jackstraw.jack_base.util.ObjectUtil;
import com.jackstraw.jack_base.util.tenant.contextholder.TenantContextHolder;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.core.RocketMQReplyListener;

public abstract class AbstractRocketMQReplyListener<R> implements RocketMQReplyListener<MessageExt, R> {

    @Override
    public R onMessage(MessageExt message) {
        if (ObjectUtil.ObjectUtilByLang3.isEmpty(message)) {
            throw new IllegalStateException("获取到的消息体为空");
        }
        String tenantName = message.getProperty("tenantName");
        TenantContextHolder.set(tenantName);

        return this.message(message);
    }

    public abstract R message(MessageExt message);

}
